<?php
namespace app\adminbackstage\controller;
/*
 * 类目
 */
use think\facade\Request;

use app\adminbackstage\model\Category;
/**
 * Description of Index
 *
 * @author asus80
 */
class CategoryController {
    //put your code here
    public function categoryList(){
        $page = Request::param('page');
        $num = Request::param('num');
        $page = 1;
        $num = 300;
        $category = new Category();
        $where = []; 
        $where[] = ['superior_id','=',0];
        $where[] = ['enable','=',1];
        $listCategory = $category->listCategory($page,$num,$where)->toArray(); 
        $listinfo = array();

     
        foreach ($listCategory as $key => $value) {
            $listinfo[$key] = array("id"=>$value['id'],"superior_id"=>"0","category"=>$value['category']);
            $where_two = []; 
            $where_two[] = ['superior_id','=',$value['id']];
            $where_two[] = ['enable','=',1];
            $listCategory_two = $category->listCategory($page,$num,$where_two)->toArray(); 
            foreach ($listCategory_two as $k => $v) {
                $listinfo[$key]['child'][] = array("id"=>$v['id'],"superior_id"=>$value['id'],"category"=>$v['category']);
            }
        }


        return json(['code' => 1, 'msg' => lang(''), 'data' => $listinfo, 'count' => '']);
    }
}
